package com.qyhl.school.school.reporter.news;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.news.NewsBean;
import com.qyhl.webtv.module_microvideo.common.VideoUrl;

import java.util.List;

public class SchoolReporterNewsModel implements SchoolReporterNewsContract.SchoolReporterNewsModel {
    private SchoolReporterNewsPresenter mPresenter;

    public SchoolReporterNewsModel(SchoolReporterNewsPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }


    @Override
    public void getData(String sectionId, String newsId) {
        EasyHttp.get(VideoUrl.GET_HOME_NEWS)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("InnerCode", sectionId)
                .params("ID", newsId)
                .params("tagName", CommonUtils.getInstance().getSiteName())
                .execute(new SimpleCallBack<List<NewsBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", (!"0".equals(newsId) && !"1".equals(newsId)));
                        } else {
                            mPresenter.setError("解析出错，加载失败！", (!"0".equals(newsId) && !"1".equals(newsId)));
                        }
                    }

                    @Override
                    public void onSuccess(List<NewsBean> newsBeans) {
                        if (newsBeans != null && newsBeans.size() > 0) {
                            mPresenter.setData(newsBeans, (!"0".equals(newsId) && !"1".equals(newsId)));
                        } else {
                            mPresenter.setError("暂无任何内容！", (!"0".equals(newsId) && !"1".equals(newsId)));
                        }
                    }
                });
    }
}
